package com.wnnight.wys.serviceImpl.room;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wnnight.wys.entity.room.Room;
import com.wnnight.wys.mapper.room.RoomMapper;
import com.wnnight.wys.service.room.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: RoomServiceImpl
 * @Description: //TODO
 * @author: CD
 * @date: 2022/8/28-20:13
 * @version: v1.0
 */
@Service
public class RoomServiceImpl extends ServiceImpl<RoomMapper, Room> implements RoomService {
    @Autowired
    private RoomMapper roomMapper;


    @Override
    public List<Room> selectRoomBYCondtion(Room room) {
        return roomMapper.selectRoomBYCondtion(room);//查询条件
    }

    @Override
    public List<Room> selectBuilding() {
        return roomMapper.selectBuilding();
    }

    @Override
    public List<Room> getfoolByunbu(Integer unitId, Integer buildingId) {
        return roomMapper.getfoolByunbu(unitId,buildingId);
    }

    @Override
    public List<Room> getfoolAllByunbu(Integer unitId, Integer buildingId) {
        return roomMapper.getfoolAllByunbu(unitId,buildingId);
    }

    @Override
    public void deleteLandId(long id) {
        roomMapper.deleteLandId(id);
    }

    @Override
    public void updateRoom11(Room room) {
        roomMapper.updateRoom11(room);
    }

    @Override
    public Room selectRoomById1(long id) {
        return roomMapper.selectRoomById1(id);
    }

    @Override
    public int selectRoomCountzc() {
        return roomMapper.selectRoomCountzc();
    }

    @Override
    public int selectRoomCountcz() {
        return roomMapper.selectRoomCountcz();
    }

    @Override
    public int selectRoomCountkx() {
        return roomMapper.selectRoomCountkx();
    }

    @Override
    public List<Room> selectByLandlordId(int landlordId) {
        return roomMapper.selectByLandlordId(landlordId);
    }

    @Override
    public List<Room> getRoomByBuildingId(Integer buildingId) {
        return roomMapper.getRoomByBuildingId(buildingId);
    }

    @Override
    public List<Room> getRoomByUnitId(Integer unitId) {
        return roomMapper.getRoomByUnitId(unitId);
    }

    @Override
    public List<Room> getRoomByFloorId(Integer floorId) {
        return roomMapper.getRoomByFloorId(floorId);
    }

    @Override
    public List<Room> selectlistRoom() {
        return roomMapper.selectlistRoom();
    }

    public RoomPageBean.PageBean<Room> selectlistRoom(Integer page, Integer size) {
        RoomPageBean.PageBean<Room> pageBean = new RoomPageBean.PageBean<>();
        Page<Room> p = PageHelper.startPage(page, size);
        List<Room> data = roomMapper.selectlistRoom();
        pageBean.setData(data);
        pageBean.setCurrPageSize(size);//当前页数
        pageBean.setCurrPage(page);//
        pageBean.setCurrPageSize(data.size());
        pageBean.setPageSize(size);
        pageBean.setTotalNums((int) p.getTotal());
        pageBean.setTotalPages(p.getPages());
        return pageBean;

    }

    //动态查找 分页
    public RoomPageBean.PageBean<Room> getPageallByCondtion(Room room, int page, int size) {
        RoomPageBean.PageBean<Room> pageBean = new RoomPageBean.PageBean<>();
        Page<Room> p = PageHelper.startPage(page, size);
        List<Room> data = roomMapper.selectRoomBYCondtion(room);
        pageBean.setData(data);
        pageBean.setCurrPageSize(size);
        pageBean.setCurrPage(page);
        pageBean.setCurrPageSize(data.size());
        pageBean.setPageSize(size);
        pageBean.setTotalNums((int) p.getTotal());
        pageBean.setTotalPages(p.getPages());
        return pageBean;
    }


    //级联 小区 分页
    public RoomPageBean.PageBean<Room> getbuild(Integer buildingId, int page, int size) {
        RoomPageBean.PageBean<Room> pageBean = new RoomPageBean.PageBean<>();
        Page<Room> p = PageHelper.startPage(page, size);
        List<Room> data = roomMapper.getRoomByBuildingId(buildingId);
        pageBean.setData(data);
        pageBean.setCurrPageSize(2);
        pageBean.setCurrPage(page);
        pageBean.setCurrPageSize(data.size());
        pageBean.setPageSize(size);
        pageBean.setTotalNums((int) p.getTotal());
        pageBean.setTotalPages(p.getPages());
        return pageBean;
    }


    //级联 单元 分页
    public RoomPageBean.PageBean<Room> getunit(Integer unitId, int page, int size) {
        RoomPageBean.PageBean<Room> pageBean = new RoomPageBean.PageBean<>();
        Page<Room> p = PageHelper.startPage(page, size);
        List<Room> data = roomMapper.getRoomByUnitId(unitId);
        pageBean.setData(data);
        pageBean.setCurrPageSize(2);
        pageBean.setCurrPage(page);
        pageBean.setCurrPageSize(data.size());
        pageBean.setPageSize(size);
        pageBean.setTotalNums((int) p.getTotal());
        pageBean.setTotalPages(p.getPages());
        return pageBean;
    }

    //级联 楼层 分页
    public RoomPageBean.PageBean<Room> getfloorId(Integer floorId, int page, int size) {
        RoomPageBean.PageBean<Room> pageBean = new RoomPageBean.PageBean<>();
        Page<Room> p = PageHelper.startPage(page, size);
        List<Room> data = roomMapper.getRoomByFloorId(floorId);
        pageBean.setData(data);
        pageBean.setCurrPageSize(2);
        pageBean.setCurrPage(page);
        pageBean.setCurrPageSize(data.size());
        pageBean.setPageSize(size);
        pageBean.setTotalNums((int) p.getTotal());
        pageBean.setTotalPages(p.getPages());
        return pageBean;
    }
}

